﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using com.pro2e.console.service.auth;
using com.pro2e.console.service.auth.vo;
using System.Collections.Generic;
using com.pro2e.console.service.msg.vo;

using com.pro2e.console.core.util;
using NHibernate.Criterion;
using com.pro2e.console.service.log;
using com.pro2e.console.service.log.vo;

public partial class adm_UC14_UC14_5_QueryLog : System.Web.UI.Page
{
    LogService logService = new LogService();
    AuthService authSevice = new AuthService();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //InitData();
            fillGridView();
        }
    }

    //private void InitData()
    //{
    //    ddlClassify.Items.Add(new ListItem("全部"));

    //    ddlClassify.Items.Add(new ListItem(MsgVO.LogTitleName.登入記錄.ToString()));

    //    IList<MenuFunc> menuList = authSevice.GetTopMenuFunc();

    //    foreach (MenuFunc menu in menuList)
    //    {
    //        ListItem item = new ListItem(menu.MenuFuncName);
    //        ddlClassify.Items.Add(item);
    //    }

    //    ddlClassify.SelectedIndex = 0;
    //    ddlClassify.DataBind();
    //}

    protected void btnQuery_Click(object sender, ImageClickEventArgs e)
    {
        fillGridView();
    }

    private void fillGridView()
    {
        //分頁
        AspNetPager1.RecordCount = logService.CountDetachedCriteriaRow(GenerateRule(true));

        int maxRecord = AspNetPager1.PageSize;
        int startIndex = AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1);

        DetachedCriteria dcriteria = GenerateRule(false);

        IList<LogSystemVO> result = logService.ExecutableDetachedCriteria<LogSystemVO>(dcriteria, startIndex, maxRecord);
        gvDetail.DataSource = result;
        gvDetail.DataBind();
    }


    private DetachedCriteria GenerateRule(bool IsPageCriteria)
    {
        DetachedCriteria dCriteria = DetachedCriteria.For(typeof(LogSystemVO));

        //有值但不為全部
        //if (!string.IsNullOrEmpty(ddlClassify.SelectedValue) && !ddlClassify.SelectedValue.Equals("全部"))
        //{
           // dCriteria.Add(Expression.Eq("Fucntion", ddlClassify.SelectedValue));
        //}


        //if (!String.IsNullOrEmpty(txtDateFrom.Text) && !string.IsNullOrEmpty(txtDateTo.Text))
        //{
           // dCriteria.Add(Expression.Ge("UpdateDate", ConvertUtil.ToDateTime(txtDateFrom.Text)));
          //  dCriteria.Add(Expression.Le("UpdateDate", ConvertUtil.ToDateTime(txtDateTo.Text)));
        //}

        if (!IsPageCriteria)
        {
            dCriteria.AddOrder(Order.Desc("UpdateDate"));
        }

        return dCriteria;
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        fillGridView();
    }


    protected void gvDetail_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        //e.Row.Attributes.Add("onmouseover", "javascript:__doPostBack('ctl00$ContentPlaceHolder1$gvDetail','Select$" + e.Row.RowIndex + "')");

    }
}
